From e9c020f08973a07cad15c8ae7c991441d20e1458 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Thu, 27 Aug 2015 01:11:09 +0800 Subject: [PATCH] bash completion for targets --- src/etc/cargo.bashcomp.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/etc/cargo.bashcomp.sh b/src/etc/cargo.bashcomp.sh index 3924e1e31..00e0067cf 100644 --- a/src/etc/cargo.bashcomp.sh +++ b/src/etc/cargo.bashcomp.sh @@ -62,6 +62,9 @@ _cargo() --example) COMPREPLY=( $( compgen -W "$(_get_examples)" -- "$cur" ) ) ;; + --target) + COMPREPLY=( $( compgen -W "$(_get_targets)" -- "$cur" ) ) + ;; help) COMPREPLY=( $( compgen -W "$__cargo_commands" -- "$cur" ) ) ;; @@ -95,4 +98,23 @@ _get_examples(){ echo "${names[@]}" fi } + +_get_targets(){ + local TARGETS=() + local FIND_PATHS=( "/" ) + local CURRENT_PATH=$(_locate_manifest) + while [[ "$CURRENT_PATH" != "/" ]]; do + FIND_PATHS+=( "$CURRENT_PATH" ) + CURRENT_PATH=$(dirname $CURRENT_PATH) + done + for FIND_PATH in ${FIND_PATHS[@]}; do + if [[ -f "$FIND_PATH"/.cargo/config ]]; then + LINES=( `grep "$FIND_PATH"/.cargo/config -e "^\[target\."` ) + for LINE in ${LINES[@]}; do + TARGETS+=(`sed 's/^\[target\.\(.*\)\]$/\1/' <<< $LINE`) + done + fi + done + echo "${TARGETS[@]}" +} # vim:ft=sh -- 2.30.2